﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace LaserGRBL.Hershey
{
	public class Hershey
	{
		private static double spbwl = 0.3;

		private static string[][] hor =
		{
			new string[] { "G0X0.4" },
			new string[] { "G0X0.056Y1.845", "M3", "G1Y0.853F1000", "M5", "G0X0.005Y0.601", "M3", "G1Y0.497", "X0.114", "Y0.601", "X0.005" },
			new string[] { "G0Y1.884", "M3", "G1X0.012Y1.469", "M5", "G0X0.325Y1.884", "M3", "G1X0.339Y1.469" },
			new string[] { "G0X0.349Y1.794", "M3", "G1X0.166Y0.49", "M5", "G0X0.765Y1.794", "M3", "G1X0.581Y0.49", "M5", "G0X0.049Y1.378", "M3", "G1X0.925", "M5", "G0X0.005Y0.964", "M3", "G1X0.874" },
			new string[] { "G0X0.693Y1.652", "M3", "G1X0.574Y1.742", "X0.452Y1.767", "X0.377Y1.773", "Y1.996", "Y1.773", "X0.224Y1.748", "X0.108Y1.652", "X0.064Y1.541", "X0.071Y1.405", "X0.129Y1.308", "X0.245Y1.23", "X0.503Y1.112", "X0.605Y1.042", "X0.684Y0.97", "X0.728Y0.853", "Y0.756", "X0.693Y0.633", "X0.568Y0.542", "X0.414Y0.496", "X0.377", "Y0.283", "Y0.496", "X0.261Y0.509", "X0.115Y0.561", "X0.005Y0.639" },
			new string[] { "G0X0.275Y1.043", "M3", "G1X0.384Y1.061", "X0.472Y1.125", "X0.53Y1.23", "X0.56Y1.372", "X0.567Y1.477", "X0.53Y1.619", "X0.472Y1.728", "X0.4Y1.794", "X0.312Y1.827", "X0.217Y1.821", "X0.108Y1.761", "X0.042Y1.671", "X0.012Y1.561", "X0.005Y1.339", "X0.027Y1.224", "X0.078Y1.133", "X0.152Y1.073", "X0.21Y1.049", "X0.275Y1.043", "M5", "G0X1.298Y0.484", "M3", "G1X1.407Y0.504", "X1.488Y0.575", "X1.553Y0.672", "X1.576Y0.814", "X1.583Y0.919", "X1.553Y1.067", "X1.495Y1.179", "X1.423Y1.242", "X1.328Y1.275", "X1.233Y1.263", "X1.131Y1.21", "X1.057Y1.119", "X1.036Y1.01", "X1.02Y0.79", "X1.05Y0.666", "X1.101Y0.581", "X1.166Y0.523", "X1.233Y0.491", "X1.298Y0.484", "M5", "G0X0.37Y0.478", "M3", "G1X1.203Y1.839" },
			new string[] { "G0X1.139Y0.503", "M3", "G1X0.969Y0.568", "X0.786Y0.705", "X0.596Y0.866", "X0.473Y1.003", "X0.32Y1.218", "X0.246Y1.372", "X0.225Y1.574", "X0.246Y1.689", "X0.327Y1.782", "X0.443Y1.821", "X0.582Y1.8", "X0.663Y1.736", "X0.7Y1.631", "X0.677Y1.522", "X0.605Y1.411", "X0.51Y1.339", "X0.232Y1.152", "X0.137Y1.073", "X0.049Y0.971", "X0.005Y0.859", "X0.027Y0.736", "X0.099Y0.601", "X0.246Y0.523", "X0.429Y0.491", "X0.568Y0.523", "X0.728Y0.607", "X0.846Y0.73", "X0.948Y0.853", "X1.027Y1.016", "X1.088Y1.158" },
			new string[] { "G0X0.005Y1.884", "M3", "G1X0.019Y1.469" },
			new string[] { "G0X0.281Y0.153", "M3", "G1X0.165Y0.348", "X0.063Y0.601", "X0.026Y0.756", "X0.005Y0.983", "Y1.197", "X0.04Y1.384", "X0.093Y1.567", "X0.172Y1.761", "X0.237Y1.872", "X0.29Y1.936" },
			new string[] { "G0X0.005Y0.147", "M3", "G1X0.13Y0.354", "X0.225Y0.575", "X0.267Y0.789", "X0.297Y1.055", "X0.26Y1.314", "X0.232Y1.483", "X0.181Y1.637", "X0.093Y1.794", "X0.005Y1.942" },
			new string[] { "G0X0.108Y1.462", "M3", "G1X0.268Y1.67", "X0.53Y1.749", "X0.268Y1.67", "Y1.917", "Y1.67", "X0.005Y1.749", "X0.268Y1.67", "X0.451Y1.456" },
			new string[] { "G0X0.451Y1.598", "M3", "G1Y0.711", "M5", "G0X0.005Y1.158", "M3", "G1X0.917" },
			new string[] { "G0X0.144Y0.51", "M3", "G1X0.056", "Y0.614", "X0.144", "X0.182Y0.497", "X0.172Y0.399", "X0.128Y0.315", "X0.07Y0.263", "X0.005Y0.211" },
			new string[] { "G0X0.005Y0.995", "M3", "G1X0.479" },
			new string[] { "G0X0.005Y0.607", "M3", "G1Y0.503", "X0.122", "Y0.607", "X0.005" },
			new string[] { "G0Y0.166", "M3", "G1X0.698Y1.917" },
			new string[] { "G0X0.386Y0.497", "M3", "G1X0.525Y0.523", "X0.671Y0.652", "X0.736Y0.789", "X0.766Y0.944", "X0.78Y1.158", "X0.766Y1.36", "X0.713Y1.553", "X0.641Y1.677", "X0.525Y1.755", "X0.42Y1.788", "X0.335Y1.782", "X0.195Y1.71", "X0.1Y1.592", "X0.034Y1.405", "X0.012Y1.209", "X0.005Y1.016", "X0.034Y0.835", "X0.107Y0.652", "X0.195Y0.568", "X0.284Y0.503", "X0.386Y0.496" },
			new string[] { "G0X0.364Y1.689", "M3", "G1X0.123Y1.683", "X0.371Y1.767", "Y0.523", "X0.005", "X0.729" },
			new string[] { "G0X0.005Y1.607", "M3", "G1X0.101Y1.689", "X0.217Y1.755", "X0.363Y1.788", "X0.488Y1.767", "X0.618Y1.71", "X0.7Y1.613", "X0.737Y1.469", "X0.727Y1.347", "X0.655Y1.197", "X0.523Y1.028", "X0.363Y0.853", "X0.217Y0.717", "X0.085Y0.588", "X0.02Y0.523", "X0.846" },
			new string[] { "G0X0.071Y1.644", "M3", "G1X0.189Y1.722", "X0.342Y1.782", "X0.465", "X0.597Y1.749", "X0.706Y1.67", "X0.757Y1.568", "X0.78Y1.444", "X0.743Y1.333", "X0.618Y1.248", "X0.481Y1.185", "X0.363Y1.164", "X0.274", "X0.386", "X0.502Y1.152", "X0.618Y1.113", "X0.743Y1.028", "X0.801Y0.95", "X0.824Y0.859", "X0.817Y0.763", "X0.794Y0.684", "X0.722Y0.594", "X0.618Y0.536", "X0.488Y0.503", "X0.349", "X0.216Y0.536", "X0.085Y0.601", "X0.005Y0.666" },
			new string[] { "G0X0.684Y0.49", "M3", "G1Y1.755", "X0.005Y0.911", "X0.925" },
			new string[] { "G0X0.005Y0.659", "M3", "G1X0.1Y0.588", "X0.202Y0.536", "X0.318Y0.497", "X0.43Y0.491", "X0.597Y0.53", "X0.713Y0.614", "X0.808Y0.736", "X0.845Y0.88", "X0.824Y1.049", "X0.743Y1.179", "X0.576Y1.263", "X0.407Y1.275", "X0.284Y1.249", "X0.158Y1.191", "X0.144Y1.21", "X0.188Y1.755", "X0.787" },
			new string[] { "G0X0.005Y1.003", "M3", "G1X0.114Y1.106", "X0.246Y1.197", "X0.378Y1.236", "X0.525", "X0.634Y1.191", "X0.715Y1.125", "X0.773Y1.003", "X0.794Y0.859", "X0.759Y0.711", "X0.678Y0.588", "X0.552Y0.51", "X0.406Y0.49", "X0.276Y0.529", "X0.158Y0.607", "X0.063Y0.736", "X0.02Y0.919", "X0.005Y1.112", "X0.034Y1.359", "X0.086Y1.508", "X0.151Y1.625", "X0.26Y1.722", "X0.399Y1.773", "X0.539Y1.781", "X0.671Y1.742", "X0.766Y1.67" },
			new string[] { "G0X0.356Y0.497", "M3", "G1X0.384Y0.841", "X0.442Y1.088", "X0.523Y1.302", "X0.626Y1.469", "X0.735Y1.625", "X0.846Y1.761", "X0.005" },
			new string[] { "G0X0.509Y1.119", "M3", "G1X0.655Y1.224", "X0.743Y1.339", "X0.764Y1.45", "X0.757Y1.567", "X0.662Y1.703", "X0.516Y1.773", "X0.4Y1.781", "X0.224Y1.736", "X0.108Y1.631", "X0.077Y1.514", "X0.114Y1.353", "X0.23Y1.254", "X0.437Y1.158", "X0.625Y1.067", "X0.75Y0.983", "X0.808Y0.865", "X0.794Y0.723", "X0.75Y0.62", "X0.611Y0.522", "X0.437Y0.49", "X0.298Y0.51", "X0.152Y0.568", "X0.041Y0.672", "X0.005Y0.783", "X0.019Y0.944", "X0.135Y1.088", "X0.23Y1.145", "X0.356Y1.197" },
			new string[] { "G0X0.034Y0.614", "M3", "G1X0.115Y0.542", "X0.247Y0.503", "X0.384Y0.49", "X0.53Y0.555", "X0.669Y0.678", "X0.751Y0.865", "X0.788Y1.094", "Y1.308", "X0.737Y1.508", "X0.649Y1.664", "X0.509Y1.755", "X0.349Y1.782", "X0.18Y1.728", "X0.078Y1.637", "X0.02Y1.522", "X0.005Y1.405", "X0.012Y1.275", "X0.092Y1.139", "X0.238Y1.055", "X0.414Y1.034", "X0.604Y1.106", "X0.72Y1.203", "X0.795Y1.288" },
			new string[] { "G0X0.005Y1.392", "M3", "G1Y1.294", "X0.115", "Y1.392", "X0.005", "M5", "G0Y0.607", "M3", "G1Y0.51", "X0.115", "Y0.607", "X0.005" },
			new string[] { "G0X0.041Y1.392", "M3", "G1Y1.288", "X0.158", "Y1.392", "X0.041", "M5", "G0X0.144Y0.51", "M3", "G1X0.056", "Y0.614", "X0.144", "X0.182Y0.497", "X0.172Y0.399", "X0.137Y0.315", "X0.07Y0.263", "X0.005Y0.211" },
			new string[] { "G0X0.925Y0.835", "M3", "G1X0.005Y1.164", "X0.925Y1.495" },
			new string[] { "G0X0.005Y1.366", "M3", "G1X0.932", "M5", "G0X0.005Y0.95", "M3", "G1X0.932" },
			new string[] { "G0X0.005Y0.835", "M3", "G1X0.917Y1.17", "X0.005Y1.495" },
			new string[] { "G0X0.239Y0.607", "M3", "G1Y0.503", "X0.355", "Y0.607", "X0.239", "M5", "G0X0.283Y0.874", "M3", "G1X0.297Y0.995", "X0.355Y1.125", "X0.517Y1.32", "X0.612Y1.456", "X0.633Y1.574", "X0.605Y1.689", "X0.531Y1.782", "X0.443Y1.833", "X0.32Y1.845", "X0.195Y1.827", "X0.092Y1.782", "X0.005Y1.709" },
			new string[] { "G0X1.079Y1.308", "M3", "G1X0.984Y0.814", "X0.868Y0.711", "X0.75Y0.659", "X0.611Y0.653", "X0.488Y0.736", "X0.451Y0.874", "X0.495Y1.08", "X0.618Y1.243", "X0.787Y1.321", "X0.933Y1.294", "X1.005Y1.236", "X1.049Y1.158", "X0.984Y0.802", "X0.998Y0.724", "X1.123Y0.64", "X1.29Y0.653", "X1.43Y0.757", "X1.525Y0.893", "X1.555Y1.062", "X1.548Y1.236", "X1.488Y1.424", "X1.385Y1.562", "X1.256Y1.665", "X1.042Y1.728", "X0.817Y1.743", "X0.618Y1.71", "X0.393Y1.607", "X0.233Y1.469", "X0.121Y1.321", "X0.034Y1.125", "X0.005Y0.959", "Y0.814", "X0.056Y0.621", "X0.144Y0.465", "X0.325Y0.322", "X0.488Y0.257", "X0.713Y0.217", "X0.926Y0.225", "X1.123Y0.315" },
			new string[] { "G0X0.005Y0.49", "M3", "G1X0.552Y1.821", "X0.875Y0.983", "X0.216", "X0.875", "X1.072Y0.49" },
			new string[] { "G0X0.005Y0.516", "M3", "G1Y1.788", "X0.43", "X0.552Y1.782", "X0.678Y1.736", "X0.78Y1.652", "X0.81Y1.553", "Y1.438", "X0.759Y1.333", "X0.648Y1.263", "X0.552Y1.224", "X0.423Y1.203", "X0.019", "X0.43", "X0.552Y1.185", "X0.699Y1.152", "X0.817Y1.08", "X0.882Y1.016", "X0.905Y0.925", "Y0.796", "X0.845Y0.672", "X0.743Y0.594", "X0.562Y0.529", "X0.43Y0.517", "X0.019" },
			new string[] { "G0X0.999Y0.659", "M3", "G1X0.846Y0.555", "X0.64Y0.49", "X0.436Y0.516", "X0.245Y0.607", "X0.099Y0.763", "X0.027Y0.925", "X0.005Y1.17", "X0.027Y1.399", "X0.122Y1.586", "X0.269Y1.728", "X0.436Y1.8", "X0.626Y1.812", "X0.795Y1.782", "X0.911Y1.716", "X0.948Y1.677" },
			new string[] { "G0X0.005Y0.523", "M3", "G1Y1.788", "X0.416", "X0.583Y1.749", "X0.708Y1.689", "X0.794Y1.613", "X0.898Y1.462", "X0.933Y1.294", "Y1.191", "X0.926Y1.055", "X0.905Y0.898", "X0.847Y0.789", "X0.743Y0.652", "X0.583Y0.568", "X0.429Y0.529", "X0.313Y0.523", "X0.012" },
			new string[] { "G0X0.78Y0.523", "M3", "G1X0.005", "Y1.191", "X0.65", "X0.005", "Y1.782", "X0.752" },
			new string[] { "G0X0.005Y0.497", "M3", "G1Y1.17", "X0.657", "X0.005", "Y1.782", "X0.752" },
			new string[] { "G0X0.603Y1.106", "M3", "G1X1.007", "Y0.626", "X0.912Y0.568", "X0.707Y0.503", "X0.561Y0.496", "X0.415Y0.522", "X0.283Y0.587", "X0.13Y0.743", "X0.027Y0.937", "X0.005Y1.163", "X0.035Y1.384", "X0.13Y1.579", "X0.283Y1.727", "X0.436Y1.793", "X0.612Y1.82", "X0.803Y1.793", "X0.919Y1.736", "X1Y1.676" },
			new string[] { "G0X0.005Y0.503", "M3", "G1Y1.8", "Y1.197", "X0.933", "Y1.794", "Y0.503" },
			new string[] { "G0X0.005Y0.497", "M3", "G1Y1.8" },
			new string[] { "G0Y0.666", "M3", "G1X0.077Y0.588", "X0.166Y0.529", "X0.282Y0.49", "X0.428Y0.51", "X0.567Y0.594", "X0.634Y0.717", "X0.648Y0.814", "Y1.806" },
			new string[] { "G0X0.005Y0.497", "M3", "G1Y1.806", "M5", "G0X0.838Y1.794", "M3", "G1X0.028Y0.983", "M5", "G0X0.378Y1.333", "M3", "G1X0.926Y0.497" },
			new string[] { "G0X0.005Y1.806", "M3", "G1Y0.523", "X0.736" },
			new string[] { "G0X0.005Y0.49", "M3", "G1Y1.806", "X0.079", "X0.552Y0.659", "X1.028Y1.8", "X1.079", "Y0.497" },
			new string[] { "G0X0.005Y0.503", "M3", "G1Y1.794", "X0.056", "X0.926Y0.503", "Y1.8" },
			new string[] { "G0X0.568Y0.503", "M3", "G1X0.758Y0.529", "X0.948Y0.639", "X1.078Y0.814", "X1.145Y1.042", "Y1.255", "X1.108Y1.43", "X1.036Y1.574", "X0.918Y1.709", "X0.758Y1.794", "X0.596Y1.821", "X0.459Y1.8", "X0.303Y1.749", "X0.16Y1.637", "X0.048Y1.45", "X0.012Y1.302", "X0.005Y1.08", "X0.034Y0.911", "X0.106Y0.756", "X0.211Y0.633", "X0.327Y0.549", "X0.452Y0.51", "X0.568Y0.504" },
			new string[] { "G0X0.012Y0.49", "M3", "G1Y1.794", "X0.532", "X0.664Y1.761", "X0.759Y1.697", "X0.831Y1.613", "X0.861Y1.483", "X0.854Y1.366", "X0.794Y1.236", "X0.685Y1.158", "X0.532Y1.106", "X0.358Y1.1", "X0.005" },
			new string[] { "G0X0.568Y0.49", "M3", "G1X0.728Y0.523", "X0.895Y0.601", "X1.035Y0.73", "X1.116Y0.911", "X1.146Y1.067", "Y1.248", "X1.116Y1.438", "X1.058Y1.567", "X0.925Y1.709", "X0.758Y1.794", "X0.603Y1.827", "X0.443Y1.8", "X0.29Y1.742", "X0.158Y1.625", "X0.079Y1.502", "X0.027Y1.308", "X0.005Y1.158", "X0.02Y1.016", "X0.072Y0.847", "X0.151Y0.705", "X0.253Y0.607", "X0.378Y0.536", "X0.501Y0.503", "X0.568Y0.496", "X0.633Y0.38", "X0.728Y0.295", "X0.83Y0.243", "X0.963Y0.21", "X1.079Y0.204", "X1.188Y0.225" },
			new string[] { "G0X0.005Y0.497", "M3", "G1Y1.794", "X0.494", "X0.613Y1.761", "X0.743Y1.703", "X0.838Y1.574", "Y1.463", "X0.817Y1.339", "X0.729Y1.23", "X0.62Y1.17", "X0.443Y1.133", "X0.012", "X0.43", "X0.854Y0.497" },
			new string[] { "G0X0.005Y0.678", "M3", "G1X0.128Y0.588", "X0.247Y0.536", "X0.393Y0.51", "X0.56Y0.504", "X0.743Y0.569", "X0.866Y0.666", "X0.91Y0.796", "X0.903Y0.911", "X0.824Y1.029", "X0.655Y1.125", "X0.356Y1.243", "X0.189Y1.34", "X0.101Y1.444", "X0.094Y1.574", "X0.152Y1.71", "X0.319Y1.801", "X0.481Y1.821", "X0.634Y1.807", "X0.75Y1.755", "X0.859Y1.683" },
			new string[] { "G0X0.509Y0.503", "M3", "G1Y1.794", "X0.005", "X1.022" },
			new string[] { "G0X0.005Y1.806", "M3", "G1Y0.905", "X0.028Y0.789", "X0.093Y0.666", "X0.181Y0.581", "X0.314Y0.516", "X0.436Y0.491", "X0.59Y0.51", "X0.745Y0.581", "X0.854Y0.699", "X0.905Y0.802", "X0.919Y0.944", "Y1.8" },
			new string[] { "G0X0.005Y1.806", "M3", "G1X0.494Y0.497", "X0.984Y1.8" },
			new string[] { "G0X0.005Y1.806", "M3", "G1X0.348Y0.497", "X0.378Y0.504", "X0.759Y1.801", "X0.787", "X1.174Y0.497", "X1.204", "X1.531Y1.807" },
			new string[] { "G0X0.005Y0.497", "M3", "G1X0.883Y1.806", "M5", "G0X0.049Y1.812", "M3", "G1X0.91Y0.497" },
			new string[] { "G0X0.005Y1.806", "M3", "G1X0.45Y1.022", "Y0.503", "Y1.028", "X0.889Y1.8" },
			new string[] { "G0X0.056Y1.794", "M3", "G1X0.933", "X0.005Y0.516", "X0.961" },
			new string[] { "G0X0.311Y0.205", "M3", "G1X0.005", "Y1.897", "X0.311" },
			new string[] { "G0X0.005Y1.911", "M3", "G1X0.699Y0.166" },
			new string[] { "G0X0.005Y0.211", "M3", "G1X0.311", "Y1.903", "X0.005" },
			new string[] { "G0Y1.1", "M3", "G1X0.348Y1.845", "X0.699Y1.08" },
			new string[] { "G0X0.005Y0.289", "M3", "G1X1.101" },
			new string[] { "G0X0.005Y1.917", "M3", "G1X0.218Y1.664" },
			new string[] { "G0X0.05Y1.339", "M3", "G1X0.203Y1.417", "X0.333Y1.45", "X0.465Y1.462", "X0.567Y1.429", "X0.655Y1.359", "X0.713Y1.254", "X0.72Y1.112", "Y0.678", "Y0.503", "X0.713Y0.678", "X0.618Y0.62", "X0.516Y0.555", "X0.4Y0.51", "X0.268Y0.49", "X0.159Y0.523", "X0.071Y0.575", "X0.005Y0.659", "Y0.783", "X0.057Y0.88", "X0.173Y0.964", "X0.289Y1.003", "X0.428Y1.043", "X0.56Y1.061", "X0.642Y1.067", "X0.706" },
			new string[] { "G0X0.005Y1.936", "M3", "G1Y0.49", "Y0.666", "X0.086Y0.607", "X0.209Y0.536", "X0.341Y0.503", "X0.471Y0.496", "X0.627Y0.574", "X0.722Y0.665", "X0.794Y0.795", "X0.824Y0.958", "X0.815Y1.118", "X0.78Y1.269", "X0.671Y1.392", "X0.576Y1.437", "X0.443Y1.462", "X0.304Y1.437", "X0.165Y1.371", "X0.019Y1.269" },
			new string[] { "G0X0.758Y0.607", "M3", "G1X0.64Y0.529", "X0.466Y0.497", "X0.304Y0.516", "X0.137Y0.614", "X0.042Y0.75", "X0.005Y0.911", "Y1.08", "X0.063Y1.236", "X0.181Y1.36", "X0.32Y1.43", "X0.473Y1.45", "X0.603Y1.43", "X0.691Y1.393", "X0.728Y1.353" },
			new string[] { "G0X0.824Y1.93", "M3", "G1Y0.503", "Y0.699", "X0.722Y0.607", "X0.583Y0.523", "X0.443Y0.49", "X0.327Y0.51", "X0.209Y0.555", "X0.093Y0.666", "X0.02Y0.814", "X0.005Y0.995", "X0.056Y1.209", "X0.181Y1.372", "X0.355Y1.45", "X0.494Y1.462", "X0.641Y1.417", "X0.736Y1.366", "X0.831Y1.287" },
			new string[] { "G0X0.02Y1.003", "M3", "G1X0.824", "Y1.119", "X0.787Y1.269", "X0.678Y1.384", "X0.567Y1.45", "X0.414Y1.456", "X0.26Y1.417", "X0.128Y1.32", "X0.077Y1.223", "X0.02Y1.1", "X0.005Y0.97", "X0.041Y0.814", "X0.107Y0.672", "X0.24Y0.555", "X0.362Y0.503", "X0.516Y0.49", "X0.648Y0.522", "X0.773Y0.581" },
			new string[] { "G0X0.179Y0.497", "M3", "G1Y1.43", "X0.005", "X0.458", "X0.172", "Y1.716", "X0.195Y1.812", "X0.267Y1.911", "X0.376Y1.948", "X0.471Y1.936", "X0.539Y1.911" },
			new string[] { "G0X0.202Y0.542", "M3", "G1X0.093Y0.451", "X0.02Y0.341", "X0.005Y0.225", "X0.107Y0.126", "X0.276Y0.063", "X0.474Y0.042", "X0.648Y0.081", "X0.824Y0.186", "X0.889Y0.283", "X0.882Y0.393", "X0.817Y0.497", "X0.654Y0.536", "X0.209", "X0.114Y0.594", "X0.07Y0.684", "X0.093Y0.769", "X0.216Y0.892", "X0.297Y0.847", "X0.423Y0.829", "X0.576Y0.874", "X0.685Y0.964", "X0.736Y1.074", "Y1.203", "X0.678Y1.321", "X0.634Y1.372", "X0.532Y1.43", "X0.882", "X0.532", "X0.423Y1.45", "X0.253Y1.438", "X0.137Y1.354", "X0.07Y1.236", "X0.063Y1.107", "X0.093Y1.004", "X0.151Y0.938", "X0.216Y0.886" },
			new string[] { "G0X0.005Y0.503", "M3", "G1Y1.93", "Y1.209", "X0.114Y1.314", "X0.209Y1.392", "X0.348Y1.444", "X0.488Y1.456", "X0.648Y1.378", "X0.706Y1.288", "X0.736Y1.139", "Y0.497" },
			new string[] { "G0X0.071Y0.49", "M3", "G1Y1.444", "M5", "G0X0.005Y1.839", "M3", "G1Y1.736", "X0.122", "Y1.839", "X0.005" },
			new string[] { "G0Y0.075", "M3", "G1X0.02", "X0.1Y0.056", "X0.21Y0.062", "X0.305Y0.12", "X0.333Y0.225", "Y1.45", "M5", "G0X0.268Y1.833", "M3", "G1Y1.736", "X0.384", "Y1.833", "X0.268" },
			new string[] { "G0X0.005Y0.49", "M3", "G1Y1.936", "M5", "G0X0.648Y1.444", "M3", "G1X0.012Y0.763", "M5", "G0X0.311Y1.088", "M3", "G1X0.729Y0.49" },
			new string[] { "G0X0.005Y1.93", "M3", "G1Y0.588", "X0.019Y0.542", "X0.042Y0.516", "X0.079Y0.497", "X0.13" },
			new string[] { "G0X0.005Y0.49", "M3", "G1Y1.444", "Y1.23", "X0.107Y1.308", "X0.202Y1.378", "X0.29Y1.43", "X0.399Y1.456", "X0.494Y1.444", "X0.559Y1.417", "X0.634Y1.353", "X0.685Y1.242", "X0.699Y1.106", "Y0.49", "Y1.209", "X0.729Y1.263", "X0.882Y1.384", "X0.998Y1.438", "X1.093Y1.462", "X1.195Y1.438", "X1.262Y1.405", "X1.341Y1.32", "X1.378Y1.152", "Y0.497" },
			new string[] { "G0X0.005Y0.49", "M3", "G1Y1.45", "Y1.218", "X0.107Y1.308", "X0.202Y1.384", "X0.276Y1.423", "X0.385Y1.45", "X0.457Y1.456", "X0.569Y1.429", "X0.634Y1.392", "X0.685Y1.326", "X0.729Y1.236", "Y0.49" },
			new string[] { "G0X0.459Y0.497", "M3", "G1X0.466", "X0.612Y0.529", "X0.751Y0.613", "X0.837Y0.744", "X0.874Y0.886", "X0.881Y1.022", "X0.86Y1.145", "X0.809Y1.255", "X0.735Y1.339", "X0.633Y1.417", "X0.524Y1.45", "X0.422Y1.456", "X0.303Y1.438", "X0.194Y1.378", "X0.099Y1.281", "X0.048Y1.19", "X0.005Y1.055", "Y0.95", "X0.019Y0.828", "X0.055Y0.717", "X0.143Y0.613", "X0.245Y0.542", "X0.357Y0.503", "X0.459Y0.496" },
			new string[] { "G0X0.005Y0.056", "M3", "G1Y1.45", "Y1.242", "X0.128Y1.353", "X0.274Y1.423", "X0.399Y1.444", "X0.552", "X0.671Y1.384", "X0.773Y1.255", "X0.824Y1.106", "Y0.938", "X0.801Y0.796", "X0.722Y0.646", "X0.603Y0.549", "X0.515Y0.51", "X0.378Y0.504", "X0.267Y0.523", "X0.144Y0.582", "X0.026Y0.653" },
			new string[] { "G0X0.824Y0.063", "M3", "G1Y1.444", "Y1.302", "X0.692Y1.384", "X0.552Y1.438", "X0.378Y1.45", "X0.216Y1.393", "X0.107Y1.275", "X0.034Y1.133", "X0.005Y1.016", "X0.012Y0.898", "X0.027Y0.775", "X0.086Y0.652", "X0.181Y0.568", "X0.283Y0.516", "X0.422Y0.49", "X0.575Y0.529", "X0.714Y0.607", "X0.817Y0.684" },
			new string[] { "G0X0.005Y0.497", "M3", "G1Y1.45", "Y1.158", "X0.072Y1.275", "X0.174Y1.392", "X0.283Y1.438", "X0.385Y1.45", "X0.45Y1.444" },
			new string[] { "G0X0.005Y0.62", "M3", "G1X0.137Y0.542", "X0.283Y0.503", "X0.399Y0.49", "X0.545Y0.536", "X0.654Y0.614", "X0.691Y0.73", "X0.664Y0.847", "X0.531Y0.944", "X0.348Y1.01", "X0.181Y1.073", "X0.086Y1.158", "X0.064Y1.255", "X0.1Y1.347", "X0.218Y1.438", "X0.362Y1.456", "X0.51Y1.43", "X0.633Y1.366" },
			new string[] { "G0X0.589Y0.536", "M3", "G1X0.51Y0.503", "X0.406", "X0.313Y0.529", "X0.232Y0.613", "X0.218Y0.756", "Y1.423", "X0.005", "X0.568", "X0.218", "Y1.716" },
			new string[] { "G0X0.713Y1.438", "M3", "G1Y0.497", "Y0.744", "X0.634Y0.659", "X0.539Y0.575", "X0.406Y0.51", "X0.281Y0.49", "X0.151Y0.523", "X0.063Y0.588", "X0.012Y0.672", "X0.005Y0.835", "Y1.438" },
			new string[] { "G0X0.005Y1.456", "M3", "G1X0.407Y0.49", "X0.435", "X0.839Y1.456" },
			new string[] { "G0X0.005Y1.45", "M3", "G1X0.325Y0.477", "X0.356", "X0.662Y1.45", "X0.706", "X1.014Y0.477", "X1.042", "X1.358Y1.45" },
			new string[] { "G0X0.005Y0.477", "M3", "G1X0.735Y1.456", "M5", "G0X0.049", "M3", "G1X0.786Y0.477" },
			new string[] { "G0X0.005Y1.444", "M3", "G1X0.445Y0.464", "M5", "G0X0.823Y1.438", "M3", "G1X0.37Y0.296", "X0.319Y0.198", "X0.247Y0.126", "X0.159Y0.081", "X0.005" },
			new string[] { "G0X0.042Y1.417", "M3", "G1X0.692", "X0.005Y0.523", "X0.743" },
			new string[] { "G0X0.488Y0.205", "M3", "G1X0.377Y0.199", "X0.261Y0.25", "X0.21Y0.354", "X0.24Y0.899", "X0.21Y0.971", "X0.152Y1.022", "X0.1Y1.043", "X0.005Y1.049", "X0.122Y1.073", "X0.21Y1.119", "X0.224Y1.203", "X0.217Y1.749", "X0.24Y1.839", "X0.342Y1.897", "X0.488" },
			new string[] { "G0X0.005Y0.005", "M3", "G1Y1.981" },
			new string[] { "G0Y0.205", "M3", "G1X0.144Y0.211", "X0.246Y0.257", "X0.276Y0.38", "X0.26Y0.886", "X0.29Y0.983", "X0.348Y1.028", "X0.436Y1.055", "X0.473", "X0.385Y1.079", "X0.304Y1.106", "X0.269Y1.178", "Y1.366", "X0.29Y1.755", "X0.225Y1.866", "X0.129Y1.903", "X0.012" },
			new string[] { "G0X0.005Y1.125", "M3", "G1X0.085Y1.209", "X0.18Y1.248", "X0.298", "X0.407Y1.164", "X0.53Y1.08", "X0.604Y1.055", "X0.692Y1.067", "X0.757Y1.119", "X0.822Y1.178" },
		};

		private static string[][] ver =
		{
			new string[] { "G0Y0.4" },
			new string[] { "G0X0.155Y0.056", "M3", "G1X1.147", "M5", "G0X1.4Y0.005", "M3", "G1X1.504", "Y0.114", "X1.4", "Y0.005" },
			new string[] { "G0X0.116", "M3", "G1X0.532Y0.012", "M5", "G0X0.116Y0.325", "M3", "G1X0.532Y0.339" },
			new string[] { "G0X0.207Y0.349", "M3", "G1X1.51Y0.166", "M5", "G0X0.207Y0.765", "M3", "G1X1.51Y0.581", "M5", "G0X0.622Y0.049", "M3", "G1Y0.925", "M5", "G0X1.036Y0.005", "M3", "G1Y0.874" },
			new string[] { "G0X0.349Y0.693", "M3", "G1X0.258Y0.574", "X0.233Y0.452", "X0.227Y0.377", "X0.005", "X0.227", "X0.252Y0.224", "X0.349Y0.108", "X0.46Y0.064", "X0.596Y0.071", "X0.693Y0.129", "X0.771Y0.245", "X0.888Y0.503", "X0.958Y0.605", "X1.03Y0.684", "X1.148Y0.728", "X1.244", "X1.368Y0.693", "X1.459Y0.568", "X1.504Y0.414", "Y0.377", "X1.718", "X1.504", "X1.491Y0.261", "X1.439Y0.115", "X1.361Y0.005" },
			new string[] { "G0X0.958Y0.275", "M3", "G1X0.939Y0.384", "X0.876Y0.472", "X0.771Y0.53", "X0.629Y0.56", "X0.524Y0.567", "X0.382Y0.53", "X0.272Y0.472", "X0.207Y0.4", "X0.174Y0.312", "X0.18Y0.217", "X0.239Y0.108", "X0.33Y0.042", "X0.439Y0.012", "X0.661Y0.005", "X0.777Y0.027", "X0.867Y0.078", "X0.927Y0.152", "X0.952Y0.21", "X0.958Y0.275", "M5", "G0X1.516Y1.298", "M3", "G1X1.497Y1.407", "X1.426Y1.488", "X1.328Y1.553", "X1.186Y1.576", "X1.081Y1.583", "X0.933Y1.553", "X0.822Y1.495", "X0.758Y1.423", "X0.725Y1.328", "X0.737Y1.233", "X0.791Y1.131", "X0.882Y1.057", "X0.991Y1.036", "X1.211Y1.02", "X1.334Y1.05", "X1.419Y1.101", "X1.477Y1.166", "X1.51Y1.233", "X1.517Y1.298", "M5", "G0X1.523Y0.37", "M3", "G1X0.161Y1.203" },
			new string[] { "G0X1.497Y1.139", "M3", "G1X1.432Y0.969", "X1.295Y0.786", "X1.135Y0.596", "X0.997Y0.473", "X0.783Y0.32", "X0.628Y0.246", "X0.427Y0.225", "X0.311Y0.246", "X0.219Y0.327", "X0.18Y0.443", "X0.2Y0.582", "X0.264Y0.663", "X0.369Y0.7", "X0.478Y0.677", "X0.589Y0.605", "X0.661Y0.51", "X0.849Y0.232", "X0.927Y0.137", "X1.03Y0.049", "X1.141Y0.005", "X1.265Y0.027", "X1.4Y0.099", "X1.478Y0.246", "X1.51Y0.429", "X1.478Y0.568", "X1.393Y0.728", "X1.271Y0.846", "X1.147Y0.948", "X0.985Y1.027", "X0.843Y1.088" },
			new string[] { "G0X0.116Y0.005", "M3", "G1X0.532Y0.019" },
			new string[] { "G0X1.847Y0.281", "M3", "G1X1.653Y0.165", "X1.4Y0.063", "X1.244Y0.026", "X1.018Y0.005", "X0.804", "X0.616Y0.04", "X0.433Y0.093", "X0.239Y0.172", "X0.128Y0.237", "X0.064Y0.29" },
			new string[] { "G0X1.853Y0.005", "M3", "G1X1.646Y0.13", "X1.426Y0.225", "X1.211Y0.267", "X0.946Y0.297", "X0.686Y0.26", "X0.517Y0.232", "X0.363Y0.181", "X0.207Y0.093", "X0.058Y0.005" },
			new string[] { "G0X0.538Y0.108", "M3", "G1X0.33Y0.268", "X0.252Y0.53", "X0.33Y0.268", "X0.083", "X0.33", "X0.252Y0.005", "X0.33Y0.268", "X0.544Y0.451" },
			new string[] { "G0X0.402Y0.451", "M3", "G1X1.289", "M5", "G0X0.843Y0.005", "M3", "G1Y0.917" },
			new string[] { "G0X1.491Y0.144", "M3", "G1Y0.056", "X1.387", "Y0.144", "X1.504Y0.182", "X1.601Y0.172", "X1.685Y0.128", "X1.737Y0.07", "X1.79Y0.005" },
			new string[] { "G0X1.005", "M3", "G1Y0.479" },
			new string[] { "G0X1.394Y0.005", "M3", "G1X1.497", "Y0.122", "X1.394", "Y0.005" },
			new string[] { "G0X1.835", "M3", "G1X0.083Y0.698" },
			new string[] { "G0X1.504Y0.386", "M3", "G1X1.478Y0.525", "X1.348Y0.671", "X1.211Y0.736", "X1.057Y0.766", "X0.843Y0.78", "X0.641Y0.766", "X0.447Y0.713", "X0.324Y0.641", "X0.246Y0.525", "X0.213Y0.42", "X0.219Y0.335", "X0.291Y0.195", "X0.408Y0.1", "X0.596Y0.034", "X0.791Y0.012", "X0.985Y0.005", "X1.166Y0.034", "X1.348Y0.107", "X1.432Y0.195", "X1.497Y0.284", "X1.504Y0.386" },
			new string[] { "G0X0.312Y0.364", "M3", "G1X0.318Y0.123", "X0.233Y0.371", "X1.478", "Y0.005", "Y0.729" },
			new string[] { "G0X0.394Y0.005", "M3", "G1X0.311Y0.101", "X0.246Y0.217", "X0.213Y0.363", "X0.233Y0.488", "X0.291Y0.618", "X0.388Y0.7", "X0.532Y0.737", "X0.653Y0.727", "X0.803Y0.655", "X0.972Y0.523", "X1.147Y0.363", "X1.283Y0.217", "X1.413Y0.085", "X1.478Y0.02", "Y0.846" },
			new string[] { "G0X0.357Y0.071", "M3", "G1X0.279Y0.189", "X0.219Y0.342", "Y0.465", "X0.252Y0.597", "X0.33Y0.706", "X0.433Y0.757", "X0.556Y0.78", "X0.668Y0.743", "X0.752Y0.618", "X0.816Y0.481", "X0.836Y0.363", "Y0.274", "Y0.386", "X0.849Y0.502", "X0.888Y0.618", "X0.972Y0.743", "X1.051Y0.801", "X1.141Y0.824", "X1.238Y0.817", "X1.316Y0.794", "X1.407Y0.722", "X1.465Y0.618", "X1.497Y0.488", "Y0.349", "X1.465Y0.216", "X1.4Y0.085", "X1.335Y0.005" },
			new string[] { "G0X1.51Y0.684", "M3", "G1X0.246", "X1.09Y0.005", "Y0.925" },
			new string[] { "G0X1.342Y0.005", "M3", "G1X1.413Y0.1", "X1.465Y0.202", "X1.504Y0.318", "X1.51Y0.43", "X1.471Y0.597", "X1.387Y0.713", "X1.264Y0.808", "X1.12Y0.845", "X0.951Y0.824", "X0.822Y0.743", "X0.737Y0.576", "X0.725Y0.407", "X0.752Y0.284", "X0.809Y0.158", "X0.791Y0.144", "X0.245Y0.188", "Y0.787" },
			new string[] { "G0X0.997Y0.005", "M3", "G1X0.894Y0.114", "X0.803Y0.246", "X0.764Y0.378", "Y0.525", "X0.81Y0.634", "X0.876Y0.715", "X0.997Y0.773", "X1.141Y0.794", "X1.289Y0.759", "X1.413Y0.678", "X1.491Y0.552", "X1.51Y0.406", "X1.471Y0.276", "X1.394Y0.158", "X1.265Y0.063", "X1.081Y0.02", "X0.888Y0.005", "X0.641Y0.034", "X0.493Y0.086", "X0.375Y0.151", "X0.279Y0.26", "X0.227Y0.399", "X0.219Y0.539", "X0.258Y0.671", "X0.33Y0.766" },
			new string[] { "G0X1.504Y0.356", "M3", "G1X1.16Y0.384", "X0.913Y0.442", "X0.699Y0.523", "X0.532Y0.626", "X0.375Y0.735", "X0.239Y0.846", "Y0.005" },
			new string[] { "G0X0.882Y0.509", "M3", "G1X0.777Y0.655", "X0.661Y0.743", "X0.55Y0.764", "X0.433Y0.757", "X0.297Y0.662", "X0.227Y0.516", "X0.219Y0.4", "X0.264Y0.224", "X0.369Y0.108", "X0.487Y0.077", "X0.647Y0.114", "X0.746Y0.23", "X0.843Y0.437", "X0.933Y0.625", "X1.018Y0.75", "X1.135Y0.808", "X1.277Y0.794", "X1.381Y0.75", "X1.478Y0.611", "X1.51Y0.437", "X1.491Y0.298", "X1.432Y0.152", "X1.329Y0.041", "X1.217Y0.005", "X1.057Y0.019", "X0.913Y0.135", "X0.855Y0.23", "X0.804Y0.356" },
			new string[] { "G0X1.387Y0.034", "M3", "G1X1.458Y0.115", "X1.497Y0.247", "X1.51Y0.384", "X1.445Y0.53", "X1.322Y0.669", "X1.135Y0.751", "X0.906Y0.788", "X0.692", "X0.493Y0.737", "X0.336Y0.649", "X0.246Y0.509", "X0.219Y0.349", "X0.272Y0.18", "X0.363Y0.078", "X0.478Y0.02", "X0.596Y0.005", "X0.725Y0.012", "X0.861Y0.092", "X0.946Y0.238", "X0.966Y0.414", "X0.894Y0.604", "X0.797Y0.72", "X0.713Y0.795" },
			new string[] { "G0X0.608Y0.005", "M3", "G1X0.707", "Y0.115", "X0.608", "Y0.005", "M5", "G0X1.394", "M3", "G1X1.491", "Y0.115", "X1.394", "Y0.005" },
			new string[] { "G0X0.608Y0.041", "M3", "G1X0.713", "Y0.158", "X0.608", "Y0.041", "M5", "G0X1.491Y0.144", "M3", "G1Y0.056", "X1.387", "Y0.144", "X1.504Y0.182", "X1.601Y0.172", "X1.685Y0.137", "X1.737Y0.07", "X1.79Y0.005" },
			new string[] { "G0X1.166Y0.925", "M3", "G1X0.836Y0.005", "X0.505Y0.925" },
			new string[] { "G0X0.635Y0.005", "M3", "G1Y0.932", "M5", "G0X1.051Y0.005", "M3", "G1Y0.932" },
			new string[] { "G0X1.166Y0.005", "M3", "G1X0.83Y0.917", "X0.505Y0.005" },
			new string[] { "G0X1.394Y0.239", "M3", "G1X1.497", "Y0.355", "X1.394", "Y0.239", "M5", "G0X1.127Y0.283", "M3", "G1X1.005Y0.297", "X0.876Y0.355", "X0.68Y0.517", "X0.544Y0.612", "X0.427Y0.633", "X0.312Y0.605", "X0.219Y0.531", "X0.167Y0.443", "X0.155Y0.32", "X0.174Y0.195", "X0.219Y0.092", "X0.291Y0.005" },
			new string[] { "G0X0.692Y1.079", "M3", "G1X1.186Y0.984", "X1.289Y0.868", "X1.342Y0.75", "X1.348Y0.611", "X1.264Y0.488", "X1.126Y0.451", "X0.92Y0.495", "X0.758Y0.618", "X0.68Y0.787", "X0.706Y0.933", "X0.764Y1.005", "X0.842Y1.049", "X1.198Y0.984", "X1.277Y0.998", "X1.361Y1.123", "X1.348Y1.29", "X1.244Y1.43", "X1.108Y1.525", "X0.939Y1.555", "X0.764Y1.548", "X0.577Y1.488", "X0.439Y1.385", "X0.336Y1.256", "X0.272Y1.042", "X0.258Y0.817", "X0.29Y0.618", "X0.393Y0.393", "X0.531Y0.233", "X0.68Y0.121", "X0.875Y0.034", "X1.042Y0.005", "X1.186", "X1.38Y0.056", "X1.536Y0.144", "X1.678Y0.325", "X1.743Y0.488", "X1.783Y0.713", "X1.775Y0.926", "X1.685Y1.123" },
			new string[] { "G0X1.51Y0.005", "M3", "G1X0.18Y0.552", "X1.018Y0.875", "Y0.216", "Y0.875", "X1.51Y1.072" },
			new string[] { "G0X1.484Y0.005", "M3", "G1X0.213", "Y0.43", "X0.219Y0.552", "X0.264Y0.678", "X0.348Y0.78", "X0.447Y0.81", "X0.562", "X0.667Y0.759", "X0.737Y0.648", "X0.777Y0.552", "X0.797Y0.423", "Y0.019", "Y0.43", "X0.816Y0.552", "X0.849Y0.699", "X0.921Y0.817", "X0.984Y0.882", "X1.075Y0.905", "X1.205", "X1.328Y0.845", "X1.406Y0.743", "X1.471Y0.562", "X1.484Y0.43", "Y0.019" },
			new string[] { "G0X1.342Y0.999", "M3", "G1X1.445Y0.846", "X1.51Y0.64", "X1.484Y0.436", "X1.393Y0.245", "X1.238Y0.099", "X1.075Y0.027", "X0.83Y0.005", "X0.602Y0.027", "X0.414Y0.122", "X0.272Y0.269", "X0.2Y0.436", "X0.188Y0.626", "X0.219Y0.795", "X0.285Y0.911", "X0.324Y0.948" },
			new string[] { "G0X1.478Y0.005", "M3", "G1X0.213", "Y0.416", "X0.252Y0.583", "X0.311Y0.708", "X0.388Y0.794", "X0.538Y0.898", "X0.707Y0.933", "X0.81", "X0.946Y0.926", "X1.102Y0.905", "X1.211Y0.847", "X1.348Y0.743", "X1.432Y0.583", "X1.471Y0.429", "X1.477Y0.313", "Y0.012" },
			new string[] { "G0X1.478Y0.78", "M3", "G1Y0.005", "X0.81", "Y0.65", "Y0.005", "X0.219", "Y0.752" },
			new string[] { "G0X1.504Y0.005", "M3", "G1X0.83", "Y0.657", "Y0.005", "X0.219", "Y0.752" },
			new string[] { "G0X0.894Y0.603", "M3", "G1Y1.007", "X1.374", "X1.432Y0.912", "X1.497Y0.707", "X1.504Y0.561", "X1.478Y0.415", "X1.413Y0.283", "X1.257Y0.13", "X1.063Y0.027", "X0.837Y0.005", "X0.617Y0.035", "X0.421Y0.13", "X0.273Y0.283", "X0.207Y0.436", "X0.18Y0.612", "X0.207Y0.803", "X0.265Y0.919", "X0.324Y1" },
			new string[] { "G0X1.497Y0.005", "M3", "G1X0.2", "X0.804", "Y0.933", "X0.207", "X1.497" },
			new string[] { "G0X1.504Y0.005", "M3", "G1X0.2" },
			new string[] { "G0X1.335", "M3", "G1X1.413Y0.077", "X1.471Y0.166", "X1.51Y0.282", "X1.491Y0.428", "X1.406Y0.567", "X1.283Y0.634", "X1.186Y0.648", "X0.194" },
			new string[] { "G0X1.504Y0.005", "M3", "G1X0.194", "M5", "G0X0.207Y0.838", "M3", "G1X1.018Y0.028", "M5", "G0X0.668Y0.378", "M3", "G1X1.504Y0.926" },
			new string[] { "G0X0.194Y0.005", "M3", "G1X1.478", "Y0.736" },
			new string[] { "G0X1.51Y0.005", "M3", "G1X0.194", "Y0.079", "X1.342Y0.552", "X0.2Y1.028", "Y1.079", "X1.504" },
			new string[] { "G0X1.497Y0.005", "M3", "G1X0.207", "Y0.056", "X1.497Y0.926", "X0.2" },
			new string[] { "G0X1.497Y0.568", "M3", "G1X1.471Y0.758", "X1.361Y0.948", "X1.186Y1.078", "X0.958Y1.145", "X0.746", "X0.571Y1.108", "X0.427Y1.036", "X0.291Y0.918", "X0.207Y0.758", "X0.18Y0.596", "X0.2Y0.459", "X0.252Y0.303", "X0.363Y0.16", "X0.55Y0.048", "X0.699Y0.012", "X0.921Y0.005", "X1.09Y0.034", "X1.244Y0.106", "X1.367Y0.211", "X1.452Y0.327", "X1.491Y0.452", "X1.497Y0.568" },
			new string[] { "G0X1.51Y0.012", "M3", "G1X0.207", "Y0.532", "X0.239Y0.664", "X0.303Y0.759", "X0.388Y0.831", "X0.517Y0.861", "X0.635Y0.854", "X0.764Y0.794", "X0.843Y0.685", "X0.894Y0.532", "X0.9Y0.358", "Y0.005" },
			new string[] { "G0X1.51Y0.568", "M3", "G1X1.478Y0.728", "X1.4Y0.895", "X1.271Y1.035", "X1.09Y1.116", "X0.933Y1.146", "X0.752", "X0.563Y1.116", "X0.433Y1.058", "X0.291Y0.925", "X0.207Y0.758", "X0.174Y0.603", "X0.2Y0.443", "X0.258Y0.29", "X0.375Y0.158", "X0.499Y0.079", "X0.692Y0.027", "X0.843Y0.005", "X0.985Y0.02", "X1.154Y0.072", "X1.296Y0.151", "X1.394Y0.253", "X1.465Y0.378", "X1.497Y0.501", "X1.504Y0.568", "X1.621Y0.633", "X1.705Y0.728", "X1.757Y0.83", "X1.79Y0.963", "X1.796Y1.079", "X1.775Y1.188" },
			new string[] { "G0X1.504Y0.005", "M3", "G1X0.207", "Y0.494", "X0.239Y0.613", "X0.297Y0.743", "X0.427Y0.838", "X0.538", "X0.661Y0.817", "X0.77Y0.729", "X0.83Y0.62", "X0.867Y0.443", "Y0.012", "Y0.43", "X1.504Y0.854" },
			new string[] { "G0X1.322Y0.005", "M3", "G1X1.413Y0.128", "X1.465Y0.247", "X1.491Y0.393", "X1.497Y0.56", "X1.432Y0.743", "X1.334Y0.866", "X1.204Y0.91", "X1.089Y0.903", "X0.972Y0.824", "X0.875Y0.655", "X0.758Y0.356", "X0.661Y0.189", "X0.556Y0.101", "X0.426Y0.094", "X0.29Y0.152", "X0.2Y0.319", "X0.179Y0.481", "X0.194Y0.634", "X0.245Y0.75", "X0.317Y0.859" },
			new string[] { "G0X1.497Y0.509", "M3", "G1X0.207", "Y0.005", "Y1.022" },
			new string[] { "G0X0.194Y0.005", "M3", "G1X1.096", "X1.211Y0.028", "X1.335Y0.093", "X1.419Y0.181", "X1.484Y0.314", "X1.51Y0.436", "X1.491Y0.59", "X1.419Y0.745", "X1.302Y0.854", "X1.199Y0.905", "X1.057Y0.919", "X0.2" },
			new string[] { "G0X0.194Y0.005", "M3", "G1X1.504Y0.494", "X0.2Y0.984" },
			new string[] { "G0X0.194Y0.005", "M3", "G1X1.504Y0.348", "X1.497Y0.378", "X0.2Y0.759", "Y0.787", "X1.503Y1.174", "Y1.204", "X0.194Y1.531" },
			new string[] { "G0X1.504Y0.005", "M3", "G1X0.194Y0.883", "M5", "G0X0.188Y0.049", "M3", "G1X1.504Y0.91" },
			new string[] { "G0X0.194Y0.005", "M3", "G1X0.978Y0.45", "X1.497", "X0.972", "X0.2Y0.889" },
			new string[] { "G0X0.207Y0.056", "M3", "G1Y0.933", "X1.484Y0.005", "Y0.961" },
			new string[] { "G0X1.796Y0.311", "M3", "G1Y0.005", "X0.104", "Y0.311" },
			new string[] { "G0X0.089Y0.005", "M3", "G1X1.835Y0.699" },
			new string[] { "G0X1.79Y0.005", "M3", "G1Y0.311", "X0.097", "Y0.005" },
			new string[] { "G0X0.9", "M3", "G1X0.155Y0.348", "X0.921Y0.699" },
			new string[] { "G0X1.711Y0.005", "M3", "G1Y1.101" },
			new string[] { "G0X0.083Y0.005", "M3", "G1X0.336Y0.218" },
			new string[] { "G0X0.661Y0.05", "M3", "G1X0.583Y0.203", "X0.55Y0.333", "X0.538Y0.465", "X0.571Y0.567", "X0.641Y0.655", "X0.746Y0.713", "X0.888Y0.72", "X1.322", "X1.497", "X1.322Y0.713", "X1.38Y0.618", "X1.445Y0.516", "X1.491Y0.4", "X1.51Y0.268", "X1.478Y0.159", "X1.426Y0.071", "X1.342Y0.005", "X1.217", "X1.121Y0.057", "X1.036Y0.173", "X0.997Y0.289", "X0.958Y0.428", "X0.939Y0.56", "X0.933Y0.642", "Y0.706" },
			new string[] { "G0X0.064Y0.005", "M3", "G1X1.51", "X1.335", "X1.394Y0.086", "X1.465Y0.209", "X1.497Y0.341", "X1.504Y0.471", "X1.426Y0.627", "X1.335Y0.722", "X1.205Y0.794", "X1.043Y0.824", "X0.882Y0.815", "X0.732Y0.78", "X0.608Y0.671", "X0.563Y0.576", "X0.538Y0.443", "X0.563Y0.304", "X0.629Y0.165", "X0.732Y0.019" },
			new string[] { "G0X1.394Y0.758", "M3", "G1X1.471Y0.64", "X1.504Y0.466", "X1.484Y0.304", "X1.387Y0.137", "X1.25Y0.042", "X1.09Y0.005", "X0.921", "X0.764Y0.063", "X0.641Y0.181", "X0.571Y0.32", "X0.55Y0.473", "X0.571Y0.603", "X0.608Y0.691", "X0.647Y0.728" },
			new string[] { "G0X0.071Y0.824", "M3", "G1X1.497", "X1.302", "X1.393Y0.722", "X1.478Y0.583", "X1.51Y0.443", "X1.491Y0.327", "X1.445Y0.209", "X1.335Y0.093", "X1.186Y0.02", "X1.005Y0.005", "X0.791Y0.056", "X0.628Y0.181", "X0.55Y0.355", "X0.538Y0.494", "X0.583Y0.641", "X0.635Y0.736", "X0.713Y0.831" },
			new string[] { "G0X0.997Y0.02", "M3", "G1Y0.824", "X0.882", "X0.731Y0.787", "X0.616Y0.678", "X0.55Y0.567", "X0.544Y0.414", "X0.583Y0.26", "X0.68Y0.128", "X0.777Y0.077", "X0.9Y0.02", "X1.03Y0.005", "X1.187Y0.041", "X1.329Y0.107", "X1.446Y0.24", "X1.497Y0.362", "X1.51Y0.516", "X1.478Y0.648", "X1.42Y0.773" },
			new string[] { "G0X1.504Y0.179", "M3", "G1X0.571", "Y0.005", "Y0.458", "Y0.172", "X0.285", "X0.188Y0.195", "X0.089Y0.267", "X0.052Y0.376", "X0.064Y0.471", "X0.089Y0.539" },
			new string[] { "G0X1.458Y0.202", "M3", "G1X1.549Y0.093", "X1.659Y0.02", "X1.775Y0.005", "X1.874Y0.107", "X1.938Y0.276", "X1.958Y0.474", "X1.919Y0.648", "X1.814Y0.824", "X1.717Y0.889", "X1.607Y0.882", "X1.504Y0.817", "X1.465Y0.654", "Y0.209", "X1.406Y0.114", "X1.316Y0.07", "X1.232Y0.093", "X1.108Y0.216", "X1.153Y0.297", "X1.172Y0.423", "X1.127Y0.576", "X1.036Y0.685", "X0.927Y0.736", "X0.797", "X0.68Y0.678", "X0.628Y0.634", "X0.571Y0.532", "Y0.882", "Y0.532", "X0.55Y0.423", "X0.562Y0.253", "X0.647Y0.137", "X0.764Y0.07", "X0.894Y0.063", "X0.997Y0.093", "X1.063Y0.151", "X1.114Y0.216" },
			new string[] { "G0X1.497Y0.005", "M3", "G1X0.071", "X0.791", "X0.686Y0.114", "X0.608Y0.209", "X0.556Y0.348", "X0.544Y0.488", "X0.622Y0.648", "X0.713Y0.706", "X0.861Y0.736", "X1.504" },
			new string[] { "G0X1.51Y0.071", "M3", "G1X0.556", "M5", "G0X0.161Y0.005", "M3", "G1X0.264", "Y0.122", "X0.161", "Y0.005" },
			new string[] { "G0X1.925", "M3", "G1Y0.02", "X1.944Y0.1", "X1.938Y0.21", "X1.88Y0.305", "X1.775Y0.333", "X0.55", "M5", "G0X0.168Y0.268", "M3", "G1X0.264", "Y0.384", "X0.168", "Y0.268" },
			new string[] { "G0X1.51Y0.005", "M3", "G1X0.064", "M5", "G0X0.556Y0.648", "M3", "G1X1.238Y0.012", "M5", "G0X0.913Y0.311", "M3", "G1X1.51Y0.729" },
			new string[] { "G0X0.071Y0.005", "M3", "G1X1.413", "X1.458Y0.019", "X1.484Y0.042", "X1.504Y0.079", "Y0.13" },
			new string[] { "G0X1.51Y0.005", "M3", "G1X0.556", "X0.771", "X0.692Y0.107", "X0.622Y0.202", "X0.571Y0.29", "X0.544Y0.399", "X0.556Y0.494", "X0.583Y0.559", "X0.647Y0.634", "X0.758Y0.685", "X0.894Y0.698", "X1.51", "X0.791", "X0.738Y0.729", "X0.616Y0.882", "X0.563Y0.998", "X0.538Y1.093", "X0.563Y1.195", "X0.596Y1.262", "X0.68Y1.341", "X0.849Y1.378", "X1.504" },
			new string[] { "G0X1.51Y0.005", "M3", "G1X0.55", "X0.783", "X0.692Y0.107", "X0.616Y0.202", "X0.577Y0.276", "X0.55Y0.385", "X0.544Y0.457", "X0.571Y0.569", "X0.608Y0.634", "X0.674Y0.685", "X0.765Y0.729", "X1.51" },
			new string[] { "G0X1.504Y0.459", "M3", "G1Y0.466", "X1.471Y0.612", "X1.387Y0.751", "X1.256Y0.837", "X1.114Y0.874", "X0.979Y0.881", "X0.855Y0.86", "X0.746Y0.809", "X0.661Y0.735", "X0.583Y0.633", "X0.55Y0.524", "X0.544Y0.422", "X0.563Y0.303", "X0.623Y0.194", "X0.719Y0.099", "X0.81Y0.048", "X0.946Y0.005", "X1.051", "X1.172Y0.019", "X1.283Y0.055", "X1.387Y0.143", "X1.459Y0.245", "X1.497Y0.357", "X1.504Y0.459" },
			new string[] { "G0X1.944Y0.005", "M3", "G1X0.55", "X0.758", "X0.647Y0.128", "X0.577Y0.274", "X0.556Y0.399", "Y0.552", "X0.616Y0.671", "X0.746Y0.773", "X0.894Y0.824", "X1.063", "X1.205Y0.801", "X1.354Y0.722", "X1.452Y0.603", "X1.491Y0.515", "X1.497Y0.378", "X1.477Y0.267", "X1.419Y0.144", "X1.348Y0.026" },
			new string[] { "G0X1.938Y0.824", "M3", "G1X0.556", "X0.699", "X0.616Y0.692", "X0.563Y0.552", "X0.55Y0.378", "X0.608Y0.216", "X0.725Y0.107", "X0.867Y0.034", "X0.985Y0.005", "X1.102Y0.012", "X1.225Y0.027", "X1.348Y0.086", "X1.432Y0.181", "X1.484Y0.283", "X1.51Y0.422", "X1.471Y0.575", "X1.393Y0.714", "X1.316Y0.817" },
			new string[] { "G0X1.504Y0.005", "M3", "G1X0.55", "X0.843", "X0.725Y0.072", "X0.608Y0.174", "X0.563Y0.283", "X0.55Y0.385", "X0.556Y0.45" },
			new string[] { "G0X1.38Y0.005", "M3", "G1X1.458Y0.137", "X1.497Y0.283", "X1.51Y0.399", "X1.465Y0.545", "X1.387Y0.654", "X1.271Y0.691", "X1.153Y0.664", "X1.057Y0.531", "X0.991Y0.348", "X0.927Y0.181", "X0.843Y0.086", "X0.746Y0.064", "X0.653Y0.1", "X0.563Y0.218", "X0.544Y0.362", "X0.571Y0.51", "X0.635Y0.633" },
			new string[] { "G0X1.465Y0.589", "M3", "G1X1.497Y0.51", "Y0.406", "X1.471Y0.313", "X1.387Y0.232", "X1.244Y0.218", "X0.577", "Y0.005", "Y0.568", "Y0.218", "X0.285" },
			new string[] { "G0X0.563Y0.712", "M3", "G1X1.504", "X1.256", "X1.342Y0.634", "X1.426Y0.538", "X1.491Y0.406", "X1.51Y0.281", "X1.478Y0.151", "X1.413Y0.063", "X1.329Y0.012", "X1.166Y0.005", "X0.563" },
			new string[] { "G0X0.544", "M3", "G1X1.51Y0.407", "Y0.435", "X0.544Y0.839" },
			new string[] { "G0X0.55Y0.005", "M3", "G1X1.523Y0.325", "Y0.356", "X0.55Y0.662", "Y0.706", "X1.523Y1.014", "Y1.042", "X0.55Y1.358" },
			new string[] { "G0X1.523Y0.005", "M3", "G1X0.544Y0.735", "M5", "G0Y0.049", "M3", "G1X1.523Y0.786" },
			new string[] { "G0X0.556Y0.005", "M3", "G1X1.536Y0.445", "M5", "G0X0.563Y0.823", "M3", "G1X1.705Y0.37", "X1.802Y0.319", "X1.874Y0.247", "X1.919Y0.159", "Y0.005" },
			new string[] { "G0X0.583Y0.042", "M3", "G1Y0.692", "X1.478Y0.005", "Y0.743" },
			new string[] { "G0X1.796Y0.488", "M3", "G1X1.802Y0.377", "X1.75Y0.261", "X1.646Y0.21", "X1.102Y0.24", "X1.03Y0.21", "X0.978Y0.152", "X0.958Y0.1", "X0.952Y0.005", "X0.927Y0.122", "X0.882Y0.21", "X0.797Y0.224", "X0.252Y0.217", "X0.161Y0.24", "X0.104Y0.342", "Y0.488" },
			new string[] { "G0X1.995Y0.005", "M3", "G1X0.019" },
			new string[] { "G0X1.796", "M3", "G1X1.79Y0.144", "X1.744Y0.246", "X1.621Y0.276", "X1.115Y0.26", "X1.018Y0.29", "X0.972Y0.348", "X0.946Y0.436", "Y0.473", "X0.921Y0.385", "X0.894Y0.304", "X0.822Y0.269", "X0.635", "X0.246Y0.29", "X0.134Y0.225", "X0.097Y0.129", "Y0.012" },
			new string[] { "G0X0.876Y0.005", "M3", "G1X0.791Y0.085", "X0.752Y0.18", "Y0.298", "X0.836Y0.407", "X0.921Y0.53", "X0.946Y0.604", "X0.933Y0.692", "X0.882Y0.757", "X0.822Y0.822" },
		};

		public static List<GrblCommand> CreateString(string text, double cX, double cY, int f_speed, int s_pow, bool horiz, string ton)
		{
			List<GrblCommand> rv = new List<GrblCommand>();

			double sizeX = 0, sizeY = 0;
			MeasureString(text, horiz, ref sizeX, ref sizeY);

			if (horiz) sizeY = 2;
			else sizeX = 2;

			rv.Add(new GrblCommand($"M5 S{s_pow} F{f_speed}")); // set power and speed (off)
			double oX = cX - sizeX / 2;
			double oY = cY - sizeY / 2;
			
			char[] ctext = text.ToCharArray();
			for (int i = 0; i < ctext.Length; i++)
			{
				char c = ctext[i];

				if (c >= 32 && c <= 126)
				{
					if (c == ' ')
						;
					double maxX = 0, maxY = 0;
					string[] charmap = horiz ? hor[c - 32] : ver[c - 32];
					charmap = ApplyOffset(charmap, oX, oY, ref maxX, ref maxY);

					foreach (string part in charmap)
					{
						string cmd = part.Replace("M3", ton);
						GrblCommand gc = new GrblCommand(cmd);
						rv.Add(gc); //add the char itself
					}
					rv.Add(new GrblCommand("M5")); //turn off after the char

					if (horiz) oX += maxX + spbwl;
					else oY += maxY + spbwl;
				}


			}
			return rv;
		}

		static void MeasureString(string text, bool horiz, ref double sizeX, ref double sizeY)
		{
			sizeX = 0;
			sizeY = 0;

			char[] ctext = text.ToCharArray();
			for (int i = 0; i < ctext.Length; i++)
			{
				char c = ctext[i];

				if (c >= 32 && c <= 126)
				{
					double maxX = 0, maxY = 0;
					string[] charmap = horiz ? hor[c - 32] : ver[c - 32];
					charmap = ApplyOffset(charmap, 0, 0, ref maxX, ref maxY); //get the size of this char

					if (horiz)
					{
						sizeX += maxX;
						sizeY = Math.Max(sizeY, maxY);

						if (i < ctext.Length - 1)
							sizeX += spbwl;
					}
					else
					{
						sizeY += maxY;
						sizeX = Math.Max(sizeX, maxX);

						if (i < ctext.Length - 1)
							sizeY += spbwl;
					}

				}
			}
		}

		static string[] ApplyOffset(string[] coordinates, double xOffset, double yOffset, ref double sizeX, ref double sizeY)
		{
			double maxX = 0;
			double minX = 0;

			double maxY = 0;
			double minY = 0;

			string[] updatedCoordinates = new string[coordinates.Length];

			for (int i = 0; i < coordinates.Length; i++)
			{
				string pattern = @"[XY]-?\d+(\.\d+)?"; // Regex pattern to match X and Y coordinates
				MatchCollection matches = Regex.Matches(coordinates[i], pattern);

				string updatedCoord = coordinates[i];
				foreach (Match match in matches)
				{
					string coord = match.Value;
					char axis = coord[0];
					double value = double.Parse(coord.Substring(1), CultureInfo.InvariantCulture);

					if (axis == 'X')
					{
						maxX = Math.Max(value, maxX);
						minX = Math.Min(value, minX);
						value += xOffset;
					}
					else if (axis == 'Y')
					{
						maxY = Math.Max(value, maxY);
						minY = Math.Min(value, minY);
						value += yOffset;
					}

					updatedCoord = updatedCoord.Replace(coord, $"{axis}{value.ToString(CultureInfo.InvariantCulture)}");
				}

				updatedCoordinates[i] = updatedCoord;
			}

			sizeX = maxX - minX;
			sizeY = maxY - minY;

			return updatedCoordinates;
		}


	}
}
